package com.lxw.station.Tmp;

import lombok.Data;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;

@Accessors(chain = true)
@Data
public class Tmp {
    private int id;
    private String name;
    private int count ;
    public void countIncrement(){
        count++;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Tmp tmp = (Tmp) o;
        System.out.println("this:"+this+" o:"+o);
        ((Tmp) o).countIncrement();
        return name.equals(tmp.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    public static void main(String[] args) {
        List<Tmp> list = new ArrayList<>();
        list.add(new Tmp().setId(1).setName("zs"));
        list.add(new Tmp().setId(2).setName("zs"));
        list.add(new Tmp().setId(3).setName("zs"));
        list.add(new Tmp().setId(4).setName("ls"));
        list.add(new Tmp().setId(5).setName("ww"));
        HashSet<Tmp> tmps = new HashSet<>(list);
        System.out.println("tmps = " + tmps);

    }
}
